package com.rmkj.trade.match.util;

import java.util.Date;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Created by Administrator on 2019/1/9.
 */
public final class IDUtils {

	private final static AtomicLong atomicLong = new AtomicLong(0);

	private final static int digit = 6;

	private final static int b = new Double(Math.pow(10, digit)).intValue();

	private final static String string_format = "%1$tY%1$tm%1$td%1$tH%1$tM%1$tS".concat("%2$0").concat(digit+"").concat("d");

	/**
	 *
	 * @return
	 */
	public static String generate(){
		long l = atomicLong.incrementAndGet();
		if (l >= b) {
			l = l % b;
		}else if (l < 0) {
			l = Math.abs(l);
		}
		return String.format(string_format, new Date(), l);
	}

	/**
	 *
	 * @param prefix
	 * @return
	 */
	public static String generate(String prefix){
		return prefix.concat(generate());
	}

	public static void main(String[] args){
		int n = 0;
		while (n < 103) {
			System.out.println(IDUtils.generate());
			n++;
		}
	}

}
